package com.example.film.mapper;

import com.example.film.entity.FillingCompany;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FillingCompanyMapper {
    //备案公司table-->fillingcompany
    //查看备案公司信息
    @Select("select id,createTime,type,filmName,companyName,scriptwriter from fillingcompany")
    List<FillingCompany> findFillingCompany();

    //分页查询备案公司信息
    @Select(" select id,createTime,type,filmName,companyName,scriptwriter from fillingcompany LIMIT #{pageSize} OFFSET #{startIndex}")
    List<FillingCompany> findFillingCompanyInfo(@Param("startIndex") Integer startIndex, @Param("pageSize") Integer pageSize);

    //根据影片类别分页显示备案公司信息
    @Select("select id, createtime, type, filmname, companyname, scriptwriter from fillingcompany where type=#{type} LIMIT #{pageSize} OFFSET #{startIndex}")
    List<FillingCompany> findFillingCompanyByType(@Param("type") String type,@Param("startIndex") Integer startIndex, @Param("pageSize") Integer pageSize);

    //根据立项时间分页显示备案公司信息
    //年份
    @Select("SELECT id, createtime, type, filmname, companyname, scriptwriter FROM fillingcompany\n" +
            "WHERE substr(createTime,1,4)=#{year} LIMIT #{pageSize} OFFSET #{startIndex}")
    List<FillingCompany> findFillingCompanyByYear(@Param("year") Integer year,@Param("startIndex") Integer startIndex, @Param("pageSize") Integer pageSize);
    //年份和月份
    @Select("SELECT id, createtime, type, filmname, companyname, scriptwriter FROM fillingcompany\n" +
            "WHERE substr(createTime,1,4)=#{year} and substr(createtime,6,2)=#{month} LIMIT #{pageSize} OFFSET #{startIndex}")
    List<FillingCompany> findFillingCompanyByCondition(@Param("year") Integer year,@Param("month") Integer month,@Param("startIndex") Integer startIndex, @Param("pageSize") Integer pageSize);

}
